package my.board;

 

import java.io.BufferedWriter;
import java.io.FileOutputStream;

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.OutputStreamWriter;

import java.io.PrintWriter;

import java.net.InetAddress;

import java.net.Socket;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

 

public class TCPClient implements Runnable{

	private static final String serverIP="211.238.142.80";
	
	private static final int serverPort = 10200;
	
	private String msg;
	
	private String imgno;
	
	public boolean bCheck;
	
	public TCPClient(String msg, String imgno){

       super();

       this.msg = msg;
       this.imgno=imgno;
       Bitmap bmp = BitmapFactory.decodeFile(msg);
       bCheck = false;
		
		
		try {
			bmp.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/mnt/sdcard/temp.jpeg")));
		} catch (Exception e) {
			// TODO: handle exception
		}
}

@Override

public void run(){

try{

           InetAddress serverAddr = InetAddress.getByName(serverIP);

           Socket sock = new Socket(serverAddr, serverPort);

           try{

            PrintWriter out = new PrintWriter(new BufferedWriter(new

            OutputStreamWriter(sock.getOutputStream())), true);

               out.println(imgno+".jpeg");

               out.flush();

                          
              File f = new File("/mnt/sdcard/temp.jpeg");
               DataInputStream dis = new DataInputStream(new
            
FileInputStream(f));

               DataOutputStream dos = new

DataOutputStream(sock.getOutputStream());

               byte[] buf = new byte[1024];

               while(dis.read(buf)>0)

               {

                  dos.write(buf);

                  dos.flush();

               }

               dos.close();
    

           }

           catch(Exception e){

               e.printStackTrace();

           }

           finally

           {
        	   bCheck = true;
              sock.close();

           }

}

catch(Exception e){

             e.printStackTrace();

}

}

}